package file;

import java.io.*;

/**
 * @time: 2019/11/28 14:44
 * @author: baozi
 * 字符转换流,指定格式读物输出文件，默认utf_8
 */
public class inputStreamReader {

    public static void main(String[] args) {
        InputStreamReader i=null;
        OutputStreamWriter w=null;
        try {
            //写出/输入转换流,不指定编码格式,默认utf_8格式
            //OutputStreamWriter wa=new OutputStreamWriter(new FileOutputStream("a.txt"),"utf-8");
            w=new OutputStreamWriter(new FileOutputStream("b.txt"),"utf-8");
            //读取
            i=new InputStreamReader(new FileInputStream("c.txt"),"gbk");
            char[] b=new char[1024];
            while (i.read(b) != -1) {
                 w.write(b);
            }
            w.write("包子gbk");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if(w!=null){
                    w.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                if(i!=null){
                    i.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

}
